package cn.dankal.lequ.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Toast;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.dankal.lequ.R;
import cn.dankal.lequ.ui.customview.Tag;

public class EditAlbumActivity extends AppCompatActivity {
    @Bind(R.id.et_addTag)
    EditText et_addTag;
    int number = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_album);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.ib_addGame, R.id.tv_addTag, R.id.iv_camera})
    public void click(View view) {
        switch (view.getId()) {
            case R.id.ib_addGame:
                Intent intent = new Intent(this, MyAppActivity.class);
                startActivity(intent);
                break;
            case R.id.tv_addTag:
                number = number + 1;
                if (number > 5) {
                    Toast.makeText(this, "不超过5个标签", Toast.LENGTH_SHORT).show();
                    number = 5;
                } else {
                    if (et_addTag.getText().toString().trim().length() > 10 || et_addTag.getText().toString().isEmpty())
                        Toast.makeText(this, "不超过5个字,不为空", Toast.LENGTH_SHORT).show();
                    else {
                        final ViewGroup vp = (ViewGroup) findViewById(R.id.custom_taglayout);
                        final Tag tag = new Tag(this);
                        tag.setTagText(et_addTag.getText().toString().trim());
                        tag.setTagDelete(true);
                        ViewGroup.MarginLayoutParams mp = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                        tag.setLayoutParams(mp);
                        tag.init();
                        tag.findViewById(R.id.iv_delete).setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                tag.setVisibility(View.GONE);
                                number = number - 1;
                                vp.requestLayout();
                            }
                        });
                        vp.addView(tag);

                    }
                }
                break;
            case R.id.iv_camera:
                Intent intent1 = new Intent(Intent.ACTION_GET_CONTENT, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent1, 0);
                break;
            default:
                break;
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Toast.makeText(this, "图片", Toast.LENGTH_SHORT).show();
//        super.onActivityResult(requestCode, resultCode, data);
    }
}
